package com.wicket.okrframework.biz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.wicket.okrframework.biz.service.dto.req.*;
import com.wicket.okrframework.biz.service.dto.res.*;
import com.wicket.okrframework.common.exception.BizException;
import com.wicket.okrframework.common.util.CommonFunctionHelper;
import com.wicket.okrframework.common.util.RedisUtil;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.wicket.okrframework.base.service.dto.req.DeptDto;
import cn.hutool.core.collection.CollectionUtil;
import com.wicket.okrframework.biz.service.nb.NbTargetCalc;
import com.wicket.okrframework.biz.service.InductionRecordService;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@Service
public class TargetCalcServiceImpl
  implements com.wicket.okrframework.biz.service.TargetCalcService {

  @Resource
  private RedisUtil redisUtil;
//@Resource
 //private MCustomFields2Service mCustomFields2Service;
@Resource
  private NbTargetCalc nbTargetCalc;
@Resource
  private InductionRecordService inductionRecordService;
/**
   * D1查询身份人员就职的部门列表(公共)[9369]
   * gen by moon at 4/10/2024, 11:11:05 PM
   */
  @Trace(operationName = "D1查询身份人员就职的部门列表(公共)")
  @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Transactional(rollbackFor=Exception.class)
  @Override
  public QueryMemberInductionDeptListComRespDto queryMemberInductionDeptListCom(QueryMemberInductionDeptListComReqDto reqDto){
    
      
      QueryReceiveFieldDetailRespDto receptionServiceRes_1 =null;
//步骤0: D1查询就职的部门列表(公共) - queryInductionDeptListCom
     QueryInductionDeptListComRespDto queryInductionDeptListComRespDto = null;
    QueryInductionDeptListComReqDto queryInductionDeptListComReqDto=new QueryInductionDeptListComReqDto();
  if(reqDto!=null){
      queryInductionDeptListComReqDto.setInductionUnitTypeCode(reqDto.getInductionUnitTypeCode());//SimpleFieldAssign//sourceId:1718277_1
queryInductionDeptListComReqDto.setOriginalRoleMemberId(reqDto.getOriginalRoleMemberId());//SimpleFieldAssign//sourceId:1718278_1
queryInductionDeptListComReqDto.setIsTransaction(reqDto.getIsTransaction());//SimpleFieldAssign//sourceId:1718279_1
queryInductionDeptListComReqDto.setSubjectLifeCycle(reqDto.getSubjectLifeCycle());//SimpleFieldAssign//sourceId:1718280_1
queryInductionDeptListComReqDto.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1718281_1
    }
  
    /*D1查询就职的部门列表(公共)[9362]   */
    
      queryInductionDeptListComRespDto = inductionRecordService.queryInductionDeptListCom(queryInductionDeptListComReqDto)/*vcase invoke isSameApp*/;
      
      
      
    
//步骤1: M1-获取接收字段（特殊方法） - queryReceiveFieldDetail
     //ModelCode: receptionService
        QueryReceiveFieldDetailRespDto receptionServiceRes = null;
    if(queryInductionDeptListComRespDto !=null){
          QueryReceiveFieldDetailReqDto receptionServiceReq=new QueryReceiveFieldDetailReqDto();
  if(queryInductionDeptListComRespDto!= null&&  queryInductionDeptListComRespDto.getOrgInductionRecordList() !=null&& !CollectionUtil.isEmpty(queryInductionDeptListComRespDto.getOrgInductionRecordList())){
      receptionServiceReq.setDeptList(//objList-to-objLists
        queryInductionDeptListComRespDto.getOrgInductionRecordList().stream().map(item -> {
      DeptDto elm = new DeptDto();
      if(item!=null){
      elm.setDeptId(item.getEntityId());//SimpleFieldAssign//sourceId:342761_2
    }
        return elm;
      }).collect(Collectors.toList()));//objList-to-objLists//sourceId:1718559_1
    }
  
    /*M1接收就职的部门出参[3715]  用于特殊方法接收上游入参。 */
    
      receptionServiceRes = nbTargetCalc.queryReceiveFieldDetail(receptionServiceReq);
      
      
      receptionServiceRes_1 = receptionServiceRes;
           }
    
QueryMemberInductionDeptListComRespDto retData = new QueryMemberInductionDeptListComRespDto();
  if(receptionServiceRes_1!= null&&  receptionServiceRes_1.getDeptList() !=null&& !CollectionUtil.isEmpty(receptionServiceRes_1.getDeptList())){
      retData.setDeptList(receptionServiceRes_1.getDeptList().stream().map(item->item.getDeptId())
        .collect(Collectors.toList()));/*list-to-strings*///sourceId:1718662_1
    }
  

  
  
return retData;
  }
  //
}
